﻿using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Ledict.ConditionExtract.Base;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Controls;
using Ledict.ConditionExtract.Frm.NodeTree;
using Ledict.ConditionExtract.Model;
using Ledict.Utility.Msg;
using Ledict.ConditionExtract.Frm;
using System.Collections.Generic;

namespace Ledict.ConditionExtract
{
    public partial class NodeTree_Case1 : BaseForm
    {
        //private NewIDBLL newid = new NewIDBLL();
        public string pid = "";

        private DataTable QuoteLawdt;
        private readonly QuoteLawRelBLL quoteLawRelBLL = new QuoteLawRelBLL();
        NodeTree_ArgumentTypeBLL ntat = new NodeTree_ArgumentTypeBLL();
        public string stiuationId = "";
        public string stiuationName = "";
        public string stiuationType = "";
        private readonly TreeDataBLL trbll = new TreeDataBLL();
        public string condition;
        public string ccName;
        private DataTable quoteLawRelDataTable;
        private string hwtype = "";
        private string hwname = "";
        private string catInid = "";
        private string catInName = "";
        private string Standardcatname = "";
        private string IsBasicLaw;
        private DateTime PromuDate1 = DateTime.Now;
        private string LostFlag1 = "";
        private string buttonName = "";
        DataTable ClauseTable = new DataTable();
        DataTable ItemTable = new DataTable();
        public string xmlPath = "";
        CaseCauseBLL ccb = new CaseCauseBLL();
        SYS_Label_LabelRelBLL bll = new SYS_Label_LabelRelBLL();
        private int rowIndex = -1;
        private SYS_QuoteLawConditionBLL sq1 = new SYS_QuoteLawConditionBLL();
        // public string tabPageName = "";
        private Int32 selectedNum = -1;
        private Int32 lawFlag = 0;
        private DateTime EnforceDate = DateTime.Now;
        private string HCode = string.Empty;

        /// <summary>
        /// 配置名称
        /// </summary>
        public string TxbConditionName { get; set; }

        /// <summary>
        /// 配置条件
        /// </summary>
        public string TxbConditionContent { get; set; }

        /// <summary>
        /// 配置说明
        /// </summary>
        public string TxbConditionExplain { get; set; }

        /// <summary>
        /// 法律库条文模糊搜索条件
        /// </summary>
        public string provCondition52 { get; set; }

        /// <summary>
        /// 行政执法库条文模糊搜索条件
        /// </summary>
        //public string provCondition12 { get; set; }


        public NodeTree_Case1()
        {
            InitializeComponent();
        }


        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QuoteLawRelAboutCase_Load(object sender, EventArgs e)
        {
            DV_QuoteLawRel.AutoGenerateColumns = false;
            DV_QuoteLawRel.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "序号", "", 50);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "条文ID", "ProvInID", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规名称", "CATName", 300, true);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规类别", "HWName", 180, true);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规ID", "CATInID", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "发布日期", "PromuDate", 150);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规类别ID", "HwType", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "标记", "LostFlag", -1);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "执行日期", "EnforceDate", -1);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规类型", "lawFlag", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规类型排序", "HCode", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "生效日期", "EffectiveDate", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "法规标准名称", "Standardcatname", 0);
            DV_QuoteLawRel.AddColumn(typeof(DataGridViewTextBoxColumn), "是否为基本法律", "IsBasicLaw", 0);

            dataGridViewData.AutoGenerateColumns = false;
            dataGridViewData.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            comboBoxCheckBoxTreeView1.TreeView.AfterExpand += new TreeViewEventHandler(TreeView_AfterExpand);


            if (ccName == "程序法")
            {
                label2.Text = "案件类型名称： ";
                panel13.Visible = false;
                btnAddCondition.Text = "添加条件";
            }
            else
            {
                if (ccName == "刑事")
                {
                    label2.Text = "节点名称： ";
                    panel13.Visible = false;
                    btnAddCondition.Text = "添加组合";

                }
                else if (ccName == "民事")
                {
                    label2.Text = "要素名称： ";
                    panel13.Visible = true;
                    cbxType.SelectedIndex = 0;
                    txbxpath.Text = xmlPath;

                }
                btnAddCondition.Text = "添加组合";
                Name1.Visible = true;
            }

            if (ccName == "程序法")
            {
                comboBoxCheckBoxTreeView1.Visible = false;
                DataTable memTable = new DataTable();
                memTable.Columns.Add(new DataColumn("CC_ID"));
                memTable.Columns.Add(new DataColumn("CC_Name"));
                memTable.Columns.Add(new DataColumn("CC_NodeType"));
                DataRow row = memTable.NewRow();
                row["CC_ID"] = stiuationId;
                row["CC_Name"] = stiuationName;
                row["CC_NodeType"] = stiuationType;
                memTable.Rows.Add(row);
                colLinkButton_DropDown1.AddElement(memTable, "CC_Name", "CC_ID", "CC_NodeType");
            }
            else
            {
                comboBoxCheckBoxTreeView1.Visible = true;
                TreeNode node = new TreeNode();
                node.Text = stiuationName + "(" + stiuationId + ")";
                if (trbll.NodeTree_Tree(stiuationId).Rows.Count > 0)//节点有无下级
                {
                    node.Nodes.Add(new TreeNode());
                }
                // node.ExpandAll();
                comboBoxCheckBoxTreeView1.TreeView.Nodes.Add(node);
            }

            CreateQuoteLawRelTable();

            CreateClauseTable();
            CreateItemTable();

            //dataGridViewTextBoxColumn22.DataSource = ClauseTable;
            //dataGridViewTextBoxColumn22.ValueMember = "clauseId";
            //dataGridViewTextBoxColumn22.DisplayMember = "OLR_Law_ClauseName";

            //dataGridViewTextBoxColumn23.DataSource = ItemTable;
            //dataGridViewTextBoxColumn23.ValueMember = "ItemId";
            //dataGridViewTextBoxColumn23.DisplayMember = "OLR_Law_ItemName";


        }

        private void TreeView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            GetTreeHeadWordsChild(e.Node, "t_Case_HeadWords");
        }

        public void GetTreeHeadWordsChild(TreeNode parentNode, string Tname)
        {
            string ss = parentNode.Text.Replace(')', ' ');
            // var dt = trbll.GetTreeHeadWords(ss.Substring(ss.IndexOf('(')+1), Tname);// 第一层
            var dt = trbll.NodeTree_Tree(ss.Substring(ss.IndexOf('(') + 1));
            var arrayDR = dt.Select();

            foreach (var caseTreeNodeRode in arrayDR)
            {
                var node = new TreeNode
                {
                    Text = LdFormat.ObjectToString(caseTreeNodeRode["name"]) + "(" + caseTreeNodeRode["id"] + ")",
                    // Tag = caseTreeNodeRode["id"]
                };

                if (trbll.NodeTree_Tree(caseTreeNodeRode["id"].ToString()).Rows.Count > 0)//第二层
                {
                    node.Nodes.Add(new TreeNode());
                }
                parentNode.Nodes.Add(node);

            }

        }
        /// <summary>
        /// 创建项表
        /// </summary>
        private void CreateItemTable()
        {
            ItemTable.Columns.Add("ItemId", typeof(Int32));
            ItemTable.Columns.Add("OLR_Law_ItemName", typeof(string));
            DataRow dr = ItemTable.NewRow();
            dr[0] = 0;
            dr[1] = "";
            DataRow dr1 = ItemTable.NewRow();
            dr1[0] = 1;
            dr1[1] = "第一项";
            DataRow dr2 = ItemTable.NewRow();
            dr2[0] = 2;
            dr2[1] = "第二项";
            DataRow dr3 = ItemTable.NewRow();
            dr3[0] = 3;
            dr3[1] = "第三项";
            DataRow dr4 = ItemTable.NewRow();
            dr4[0] = 4;
            dr4[1] = "第四项";
            DataRow dr5 = ItemTable.NewRow();
            dr5[0] = 5;
            dr5[1] = "第五项";
            DataRow dr6 = ItemTable.NewRow();
            dr6[0] = 6;
            dr6[1] = "第六项";
            DataRow dr7 = ItemTable.NewRow();
            dr7[0] = 7;
            dr7[1] = "第七项";
            DataRow dr8 = ItemTable.NewRow();
            dr8[0] = 8;
            dr8[1] = "第八项";
            DataRow dr9 = ItemTable.NewRow();
            dr9[0] = 9;
            dr9[1] = "第九项";
            DataRow dr10 = ItemTable.NewRow();
            dr10[0] = 10;
            dr10[1] = "第十项";
            DataRow dr11 = ItemTable.NewRow();
            dr11[0] = 11;
            dr11[1] = "第十一项";
            DataRow dr12 = ItemTable.NewRow();
            dr12[0] = 12;
            dr12[1] = "第十二项";
            DataRow dr13 = ItemTable.NewRow();
            dr13[0] = 13;
            dr13[1] = "第十三项";
            DataRow dr14 = ItemTable.NewRow();
            dr14[0] = 14;
            dr14[1] = "第十四项";
            DataRow dr15 = ItemTable.NewRow();
            dr15[0] = 15;
            dr15[1] = "第十五项";
            DataRow dr16 = ItemTable.NewRow();
            dr16[0] = 16;
            dr16[1] = "第十六项";
            DataRow dr17 = ItemTable.NewRow();
            dr17[0] = 17;
            dr17[1] = "第十七项";
            DataRow dr18 = ItemTable.NewRow();
            dr18[0] = 18;
            dr18[1] = "第十八项";
            DataRow dr19 = ItemTable.NewRow();
            dr19[0] = 19;
            dr19[1] = "第十九项";
            DataRow dr20 = ItemTable.NewRow();
            dr20[0] = 20;
            dr20[1] = "第二十项";
            ItemTable.Rows.Add(dr);
            ItemTable.Rows.Add(dr1);
            ItemTable.Rows.Add(dr2);
            ItemTable.Rows.Add(dr3);
            ItemTable.Rows.Add(dr4);
            ItemTable.Rows.Add(dr5);
            ItemTable.Rows.Add(dr6);
            ItemTable.Rows.Add(dr7);
            ItemTable.Rows.Add(dr8);
            ItemTable.Rows.Add(dr9);
            ItemTable.Rows.Add(dr10);
            ItemTable.Rows.Add(dr11);
            ItemTable.Rows.Add(dr12);
            ItemTable.Rows.Add(dr13);
            ItemTable.Rows.Add(dr14);
            ItemTable.Rows.Add(dr15);
            ItemTable.Rows.Add(dr16);
            ItemTable.Rows.Add(dr17);
            ItemTable.Rows.Add(dr18);
            ItemTable.Rows.Add(dr19);
            ItemTable.Rows.Add(dr20);
        }

        /// <summary>
        /// 创建款表
        /// </summary>
        private void CreateClauseTable()
        {
            ClauseTable.Columns.Add("clauseId", typeof(Int32));
            ClauseTable.Columns.Add("OLR_Law_ClauseName", typeof(string));
            DataRow dr = ClauseTable.NewRow();
            dr[0] = 0;
            dr[1] = "";
            DataRow dr1 = ClauseTable.NewRow();
            dr1[0] = 1;
            dr1[1] = "第一款";
            DataRow dr2 = ClauseTable.NewRow();
            dr2[0] = 2;
            dr2[1] = "第二款";
            DataRow dr3 = ClauseTable.NewRow();
            dr3[0] = 3;
            dr3[1] = "第三款";
            DataRow dr4 = ClauseTable.NewRow();
            dr4[0] = 4;
            dr4[1] = "第四款";
            DataRow dr5 = ClauseTable.NewRow();
            dr5[0] = 5;
            dr5[1] = "第五款";
            DataRow dr6 = ClauseTable.NewRow();
            dr6[0] = 6;
            dr6[1] = "第六款";
            DataRow dr7 = ClauseTable.NewRow();
            dr7[0] = 7;
            dr7[1] = "第七款";
            DataRow dr8 = ClauseTable.NewRow();
            dr8[0] = 8;
            dr8[1] = "第八款";
            DataRow dr9 = ClauseTable.NewRow();
            dr9[0] = 9;
            dr9[1] = "第九款";
            DataRow dr10 = ClauseTable.NewRow();
            dr10[0] = 10;
            dr10[1] = "第十款";
            DataRow dr11 = ClauseTable.NewRow();
            dr11[0] = 11;
            dr11[1] = "第十一款";
            DataRow dr12 = ClauseTable.NewRow();
            dr12[0] = 12;
            dr12[1] = "第十二款";
            DataRow dr13 = ClauseTable.NewRow();
            dr13[0] = 13;
            dr13[1] = "第十三款";
            DataRow dr14 = ClauseTable.NewRow();
            dr14[0] = 14;
            dr14[1] = "第十四款";
            DataRow dr15 = ClauseTable.NewRow();
            dr15[0] = 15;
            dr15[1] = "第十五款";
            DataRow dr16 = ClauseTable.NewRow();
            dr16[0] = 16;
            dr16[1] = "第十六款";
            DataRow dr17 = ClauseTable.NewRow();
            dr17[0] = 17;
            dr17[1] = "第十七款";
            DataRow dr18 = ClauseTable.NewRow();
            dr18[0] = 18;
            dr18[1] = "第十八款";
            DataRow dr19 = ClauseTable.NewRow();
            dr19[0] = 19;
            dr19[1] = "第十九款";
            DataRow dr20 = ClauseTable.NewRow();
            dr20[0] = 20;
            dr20[1] = "第二十款";
            ClauseTable.Rows.Add(dr);
            ClauseTable.Rows.Add(dr1);
            ClauseTable.Rows.Add(dr2);
            ClauseTable.Rows.Add(dr3);
            ClauseTable.Rows.Add(dr4);
            ClauseTable.Rows.Add(dr5);
            ClauseTable.Rows.Add(dr6);
            ClauseTable.Rows.Add(dr7);
            ClauseTable.Rows.Add(dr8);
            ClauseTable.Rows.Add(dr9);
            ClauseTable.Rows.Add(dr10);
            ClauseTable.Rows.Add(dr11);
            ClauseTable.Rows.Add(dr12);
            ClauseTable.Rows.Add(dr13);
            ClauseTable.Rows.Add(dr14);
            ClauseTable.Rows.Add(dr15);
            ClauseTable.Rows.Add(dr16);
            ClauseTable.Rows.Add(dr17);
            ClauseTable.Rows.Add(dr18);
            ClauseTable.Rows.Add(dr19);
            ClauseTable.Rows.Add(dr20);
        }

        /// <summary>
        /// 显示来源列表        
        /// </summary>
        /// <param name="CC_ID"></param>
        private void ShowRelationLaw(NodeTreeCaseConditionData conditionData)
        {
            DataTable dt = quoteLawRelBLL.GetQuoteData(conditionData);
            if (dt != null && dt.Rows.Count > 0)
            {
                //dt.Columns.Add("showindex");
                //for (int i = 0; i < dt.Rows.Count; i++)
                //{
                //    dt.Rows[i]["showindex"] = i + 1;
                //}
                DV_QuoteLawRel.DataSource = dt;
                this.treeView1.Nodes.Clear();
                dataGridViewData.DataSource = new DataTable();
            }
            else
            {
                this.treeView1.Nodes.Clear();
                DV_QuoteLawRel.DataSource = dataGridViewData.DataSource = new DataTable();
                MsgBox.Warn("未查找到相关法规数据");

            }
        }

        private void DV_QuoteLawReldataPager1_PageNumberChanging(object sender, DataPagerPageIndexChangingEventArgs e)
        {
            if (stiuationId != "")
            {
                var startRowIndex = e.StartRowIndex;
                var maximumRows = e.MaximumRows;
                var endRowIndex = e.StartRowIndex + e.MaximumRows;
                if (QuoteLawdt == null)
                    QuoteLawdt = quoteLawRelBLL.QuoteLawRelAboutCaseList(stiuationId, stiuationName, stiuationType, pid,
                        1);

                DV_QuoteLawRel.DataSource = QuoteLawdt;

                if (QuoteLawdt.Rows.Count > 0)
                {
                    e.TotalCount = QuoteLawdt.Rows.Count;
                    var newdt = new DataTable();
                    newdt = QuoteLawdt.Clone();
                    var dr = QuoteLawdt.Select("showindex>" + startRowIndex + " and showindex<=" + endRowIndex);
                    for (var i = 0; i < dr.Length; i++)
                    {
                        newdt.ImportRow(dr[i]);
                    }
                    var ProvContentDt = quoteLawRelBLL.QuoteLawRel_ProvContent(newdt, stiuationId);
                    DV_QuoteLawRel.DataSource = ProvContentDt;
                }
                else
                {
                    MessageBox.Show("没有查询结果！");
                    DV_QuoteLawRel.DataSource = new DataTable();
                }
            }
        }

        private void allSelect_Click(object sender, EventArgs e)
        {
            var ChooseWhere = GetWhere(1);
            QuoteLawdt = quoteLawRelBLL.GetAllByWhere(ChooseWhere);
            ProvText.Text = "";
            // DV_QuoteLawReldataPager1.ChangePageNumber(1);
        }

        private void NotallSelect_Click(object sender, EventArgs e)
        {
            var ChooseWhere = GetWhere(0);
            QuoteLawdt = quoteLawRelBLL.GetAllByWhere(ChooseWhere);
            ProvText.Text = "";

            //DV_QuoteLawReldataPager1.ChangePageNumber(1);
        }

        private string GetWhere(int isallProv)
        {
            var ChooseWhere = new StringBuilder();
            ChooseWhere.Append(" 1=1 ");
            //var ChooseHWType = new StringBuilder();
            //var ChooseProv = new StringBuilder();
            //var isallHWType = 0;

            //#region 类别

            //var collection = checkedListBox1.CheckedItems;

            //for (var i = 0; i < collection.Count; i++)
            //{
            //    var dr = (DataRowView)collection[i];
            //    if (string.IsNullOrEmpty(dr.Row["HWType"].ToString())) //包含全部
            //    {
            //        isallHWType = 1;
            //        break;
            //    }
            //    if (ChooseHWType.ToString() != "")
            //    {
            //        ChooseHWType.Append(",");
            //    }
            //    ChooseHWType.Append(dr.Row["HWType"]);
            //}
            //if (collection.Count > 0 && isallHWType == 0)
            //    ChooseWhere.Append(" and HWType in (" + ChooseHWType + ")");

            //#endregion

            //if (!string.IsNullOrEmpty(LawKeyWord.Text.Trim()))
            //    ChooseWhere.Append(" and CATName like '%" + LawKeyWord.Text.Trim() + "%'"); //法律名称

            //ChooseWhere.Append(" and   PromuDate >='" + Convert.ToDateTime(PromuDateStart.Text).ToString("yyyy-MM-dd") +
            //                   "' and PromuDate <='" + Convert.ToDateTime(PromuDateEnd.Text).ToString("yyyy-MM-dd") +
            //                   "'"); //公布时间

            //#region 条文内容

            //if (!string.IsNullOrEmpty(ProvKeyWord.Text.Trim()))
            //{
            //    var provArr = ProvKeyWord.Text.Split(',', '，', ' ', ' ');

            //    foreach (var item in provArr)
            //    {
            //        if (!string.IsNullOrEmpty(item))
            //        {
            //            if (ChooseProv.ToString() != "")
            //            {
            //                if (ProvAnd.Checked)
            //                    ChooseProv.Append(" and ");
            //                else
            //                    ChooseProv.Append(" or ");
            //            }
            //            ChooseProv.Append(" ProvText like'%" + item + "%'");
            //        }
            //    }

            //    ChooseWhere.Append(" and (  ");
            //    ChooseWhere.Append(ChooseProv);
            //    ChooseWhere.Append(" )");
            //}

            //#endregion

            //if (isallProv == 0)
            //{
            //    var quoteLawRelallProv = quoteLawRelBLL.QuoteLawRelGetProv(stiuationId);
            //    if (quoteLawRelallProv != "")
            //        ChooseWhere.Append(" and  a.ProvInID not in (" + quoteLawRelallProv + ")");
            // }
            return ChooseWhere.ToString();
        }

        /// <summary>
        /// 定位事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocateWord_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ProvText.SelectionStart = 0;
            ProvText.SelectionLength = ProvText.Text.Length;
            ProvText.SelectionBackColor = Color.White;
            MatchCollection mc;
            var r = new System.Text.RegularExpressions.Regex(SelectWord.Text.Trim()); //定义一个Regex对象实例
            mc = r.Matches(ProvText.Text);
            for (var i = 0; i < mc.Count; i++) //在输入字符串中找到所有匹配
            {
                var start = mc[i].Index; //记录匹配字符的位置
                var length = (SelectWord.Text.Trim()).Length;
                ProvText.SelectionStart = start;
                ProvText.SelectionLength = length;
                ProvText.SelectionBackColor = Color.LightSkyBlue;
            }
        }

        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetData_Click(object sender, EventArgs e)
        {
            NodeTreeCaseCondition ntc = new NodeTreeCaseCondition();
            var dialogResult = ntc.ShowDialog();
            if (dialogResult == DialogResult.Yes)
            {
                this.Cursor = Cursors.WaitCursor;
                NodeTreeCaseConditionData nodeTreeCaseCondition = ntc.conditionDataModel;
                provCondition52 = nodeTreeCaseCondition.LpText;
                ShowRelationLaw(nodeTreeCaseCondition);

                this.Cursor = Cursors.Default;
                dataGridViewData.DataSource = new DataTable();
                quoteLawRelDataTable.Clear();
            }
            buttonName = "查询";
            selectedNum = -1;
            //this.treeView1.Nodes.Clear();
            //dataGridViewData.DataSource = new DataTable();
        }

        /// <summary>
        /// 推送按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTuiSong_Click(object sender, EventArgs e)
        {
            //if (stiuationType != "2")
            //{
            //    MsgBox.Warn("当前选择的节点类型不是案由，请重新选择！");
            //    return;
            //}    
            this.Cursor = Cursors.WaitCursor;
            StringBuilder str = new StringBuilder();
            DataTable dt = quoteLawRelBLL.GetQuoteTuiSongData(stiuationType == "2" ? stiuationId : ccb.IsParentRealation1(stiuationId).CC_ID);
            //dt.Select("").CopyToDataTable<DataRow>();
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow item in dt.Rows)
                {
                    str.Append("'" + item["DataId"] + "',");
                }
                string s = str.ToString().Remove(str.Length - 1);
                DataTable dt1 = quoteLawRelBLL.GetQuoteData1(s);
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    dt1.Columns.Add("showindex");
                    for (int i = 0; i < dt1.Rows.Count; i++)
                    {
                        dt1.Rows[i]["showindex"] = i + 1;
                    }
                    DV_QuoteLawRel.DataSource = dt1;
                }
            }
            else
            {
                MsgBox.Warn("未查询到对应的法律法规信息！");
            }

            this.Cursor = Cursors.Default;
            buttonName = "推送";
            this.treeView1.Nodes.Clear();
            dataGridViewData.DataSource = new DataTable();
            quoteLawRelDataTable.Clear();
        }

        /// <summary>
        /// 添加按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool res = false;
            if (quoteLawRelDataTable != null && quoteLawRelDataTable.Rows.Count > 0)
            {
                if (ccName == "刑事" || ccName == "行政执法")
                {
                    for (int i = 0; i < quoteLawRelDataTable.Rows.Count; i++)
                    {
                        if (quoteLawRelDataTable.Rows[i]["Name1"].ToString() == "单一")
                        {
                            SYS_QuoteLawRel sq = new SYS_QuoteLawRel
                            {
                                QLR_ID = quoteLawRelDataTable.Rows[i]["QLR_ID"].ToString(),
                                OLR_CaseCauseID = stiuationType == "2" ? quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString() : ccb.IsParentRealation1(quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString()).CC_ID,
                                OLR_SituationTypeID = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["OLR_SituationTypeID"].ToString()),
                                OLR_SituationID = quoteLawRelDataTable.Rows[i]["OLR_SituationID"].ToString(),
                                OLR_LawID = quoteLawRelDataTable.Rows[i]["CATInID"].ToString(),
                                //OLR_LawName = quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修订") ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（")) : quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修正") ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（")) : quoteLawRelDataTable.Rows[i]["CATName"].ToString(),
                                OLR_LawName = quoteLawRelDataTable.Rows[i]["Standardcatname"].ToString(),
                                OLR_Law_ProvID = quoteLawRelDataTable.Rows[i]["ProvInID"].ToString(),
                                OLR_Law_ProvName = quoteLawRelDataTable.Rows[i]["ProvInName"].ToString(),
                                OLR_Law_ClauseNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString(),
                                //OLR_Law_ClauseNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString(),
                                OLR_Law_ClauseName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue.ToString(),
                                //OLR_Law_ItemNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                //OLR_Law_ItemNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString(),
                                // OLR_Law_ItemName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].FormattedValue.ToString(),
                                OLR_Law_ItemNumber = quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                OLR_Law_ItemName = quoteLawRelDataTable.Rows[i]["OLR_Law_ItemName"].ToString(),
                                OLR_Law_HWType = quoteLawRelDataTable.Rows[i]["HWType"].ToString(),
                                OLR_Law_HWName = quoteLawRelDataTable.Rows[i]["HWName"].ToString(),
                                OLR_Law_PromuDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["PromuDate"].ToString()),
                                OLR_Law_LostFlag = quoteLawRelDataTable.Rows[i]["LostFlag"].ToString(),
                                OLR_Law_ProvNumber = quoteLawRelDataTable.Rows[i]["OLR_Law_ProvNumber"].ToString(),
                                OLR_LawFlag = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["lawFlag"]),
                                OLR_LawEffectiveDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["EnforceDate"].ToString()),
                                QLR_IsBasicLaw = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"].ToString()) ? DBNull.Value : quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"],
                                HCode = quoteLawRelDataTable.Rows[i]["HCode"].ToString(),
                                QLR_ProvType = quoteLawRelDataTable.Rows[i]["QLR_ProvType"].ToString()
                            };
                            sq.OLR_LevelID = !string.IsNullOrEmpty(sq.OLR_Law_ItemNumber) ? 4 : !string.IsNullOrEmpty(sq.OLR_Law_ClauseNumber) ? 3 : !string.IsNullOrEmpty(sq.OLR_Law_ProvID) ? 2 : 1;
                            if (!quoteLawRelBLL.IsExistsP(ccName, quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString(), sq.OLR_Law_ProvID, sq.OLR_Law_ClauseNumber, sq.OLR_Law_ItemNumber, ""))
                            {
                                if (ccName == "刑事")
                                {
                                    if (quoteLawRelBLL.IsExistsProv(ccName, quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString(), sq.OLR_Law_ProvID))
                                    {
                                        if (MessageBox.Show("已存在" + "《" + sq.OLR_LawName + "》" + sq.OLR_Law_ProvName + ",确认添加？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                                        {
                                            res = quoteLawRelBLL.Add(sq);
                                        }
                                        else
                                        {
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        res = quoteLawRelBLL.Add(sq);
                                    }
                                }
                                else if (ccName == "行政执法")
                                {
                                    res = quoteLawRelBLL.Add(sq);
                                }
                            }
                            else
                            {
                                if (ccName == "行政执法")
                                {
                                    if (MessageBox.Show("已存在" + "《" + sq.OLR_LawName + "》" + sq.OLR_Law_ProvName + ",确认添加？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                                    {
                                        res = quoteLawRelBLL.Add(sq);
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        else if (quoteLawRelDataTable.Rows[i]["Name1"].ToString() != "单一")
                        {

                            SYS_QuoteLawRel sq = new SYS_QuoteLawRel
                            {
                                QLR_ID = quoteLawRelDataTable.Rows[i]["QLR_ID"].ToString(),
                                //程序法不保存ID和typeid
                                // OLR_CaseCauseID = sllModel.LLR_CaseCauseID,
                                //OLR_SituationTypeID = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["OLR_SituationTypeID"].ToString()),
                                OLR_LawID = quoteLawRelDataTable.Rows[i]["CATInID"].ToString(),
                                OLR_LawName = quoteLawRelDataTable.Rows[i]["Standardcatname"].ToString(),
                                //OLR_LawName = quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修订") ?
                                //                    quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（"))
                                //                    : quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修正")
                                //                    ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（"))
                                //                    : quoteLawRelDataTable.Rows[i]["CATName"].ToString(),
                                OLR_Law_ProvID = quoteLawRelDataTable.Rows[i]["ProvInID"].ToString(),
                                OLR_Law_ProvName = quoteLawRelDataTable.Rows[i]["ProvInName"].ToString(),
                                OLR_Law_ClauseNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString(),
                                //OLR_Law_ClauseNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString()) ? ""
                                //                        : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString(),
                                OLR_Law_ClauseName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue.ToString(),
                                //OLR_Law_ItemNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                ////OLR_Law_ItemNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells[5].Value.ToString(),
                                //OLR_Law_ItemName = dataGridViewData.Rows[i].Cells[5].FormattedValue == null ? ""
                                //                        : dataGridViewData.Rows[i].Cells[5].FormattedValue.ToString(),
                                OLR_Law_ItemNumber = quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                OLR_Law_ItemName = quoteLawRelDataTable.Rows[i]["OLR_Law_ItemName"].ToString(),
                                OLR_Law_HWType = quoteLawRelDataTable.Rows[i]["HWType"].ToString(),
                                OLR_Law_HWName = quoteLawRelDataTable.Rows[i]["HWName"].ToString(),
                                OLR_Law_PromuDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["PromuDate"].ToString()),
                                OLR_Law_LostFlag = quoteLawRelDataTable.Rows[i]["LostFlag"].ToString(),
                                OLR_Law_ProvNumber = quoteLawRelDataTable.Rows[i]["OLR_Law_ProvNumber"].ToString(),
                                OLR_LawFlag = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["lawFlag"]),
                                OLR_LawEffectiveDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["EnforceDate"].ToString()),
                                HCode = quoteLawRelDataTable.Rows[i]["HCode"].ToString(),
                                QLR_IsBasicLaw = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"].ToString()) ? DBNull.Value : quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"],
                                QLR_ProvType = quoteLawRelDataTable.Rows[i]["QLR_ProvType"].ToString()
                            };
                            sq.OLR_LevelID = !string.IsNullOrEmpty(sq.OLR_Law_ItemNumber) ? 4 : !string.IsNullOrEmpty(sq.OLR_Law_ClauseNumber) ? 3 : !string.IsNullOrEmpty(sq.OLR_Law_ProvID) ? 2 : 1;

                            ccName = "组合";
                            if (quoteLawRelBLL.IsExistsP(ccName, "", sq.OLR_Law_ProvID, sq.OLR_Law_ClauseNumber, sq.OLR_Law_ItemNumber, quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString(), ""))
                            {
                                continue;
                            }
                            else
                            {
                                SYS_QuoteLawCondition sqlModel = new SYS_QuoteLawCondition
                                {
                                    QLC_ID = Guid.NewGuid().ToString(),
                                    QLC_CaseType = ccName == "程序法" ? quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString() : "",
                                    QLC_Name = dataGridViewData.Rows[i].Cells["Name1"].Value == null ? "" : dataGridViewData.Rows[i].Cells["Name1"].Value.ToString(),
                                    QLC_Content = dataGridViewData.Rows[i].Cells["txbConditionContent"].Value == null ? "" : dataGridViewData.Rows[i].Cells["txbConditionContent"].Value.ToString(),
                                    QLC_Explain = dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value == null ? "" : dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value.ToString(),
                                    QLC_CaseCauseId = ccName == "组合" ? stiuationType == "2" ? quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString() : ccb.IsParentRealation1(quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString()).CC_ID : "",
                                };
                                if (string.IsNullOrEmpty(sqlModel.QLC_Name) || string.IsNullOrEmpty(sqlModel.QLC_Content) || string.IsNullOrEmpty(sqlModel.QLC_Explain))
                                {
                                    MessageBox.Show("请将配置条件配置完整后再试!");
                                    this.dataGridViewData.Rows[i].DefaultCellStyle.BackColor = Color.GreenYellow;
                                    return;
                                }
                                //string s1= dataGridViewData.Rows[i].Cells["Name1"].Value.ToString();
                                //string s2 = dataGridViewData.Rows[i].Cells["txbConditionContent"].Value.ToString();
                                //string s3 = dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value.ToString();
                                sq.OLR_SituationID = sqlModel.QLC_ID.ToString();

                                if (sq1.AddSYS_QuoteLawCondition(sqlModel))
                                {
                                    res = quoteLawRelBLL.Add(sq);
                                }
                            }


                        }
                    }
                }
                else if (ccName == "民事"|| ccName == "组合")
                {
                    //if (string.IsNullOrEmpty(txbxpath.Text))
                    //{
                    //    MsgBox.Warn("xpath不能为空！");
                    //    return;
                    //}
                    //string ss1 = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");
                    //string ss = DateTime.Now.ToString("yyyyMMddHHmssff");
                    //ccb.ccb.IsParentRealation1(                            quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString())

                    for (int i = 0; i < quoteLawRelDataTable.Rows.Count; i++)
                    {
                        if (quoteLawRelDataTable.Rows[i]["Name1"].ToString() == "单一")
                        {
                            SYS_Label_LabelRel sllModel = new SYS_Label_LabelRel
                            {
                                LLR_ID = Guid.NewGuid().ToString(),
                                LLR_LawLabelID = Guid.NewGuid().ToString(),
                                LLR_LawLabelName = quoteLawRelDataTable.Rows[i]["MinShiDesc"].ToString(),
                                LLR_FactLabelXpath = quoteLawRelDataTable.Rows[i]["MinShiXpath"].ToString(),
                                LLR_CaseCauseID = stiuationType == "2" ? quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString() : ccb.IsParentRealation1(quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString()).CC_ID,
                            };
                            if (bll.AddSysLabelRel(sllModel, Gvar.uo.m_loginName))
                            {
                                SYS_QuoteLawRel sq = new SYS_QuoteLawRel
                                {
                                    QLR_ID = quoteLawRelDataTable.Rows[i]["QLR_ID"].ToString(),
                                    OLR_CaseCauseID = sllModel.LLR_CaseCauseID,
                                    //民事不需要保存ID
                                    //OLR_SituationTypeID = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["OLR_SituationTypeID"].ToString()),
                                    OLR_SituationID = sllModel.LLR_LawLabelID,
                                    OLR_LawID = quoteLawRelDataTable.Rows[i]["CATInID"].ToString(),
                                    OLR_LawName = quoteLawRelDataTable.Rows[i]["Standardcatname"].ToString(),
                                    //OLR_LawName = quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修订") ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（")) : quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修正") ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（")) : quoteLawRelDataTable.Rows[i]["CATName"].ToString(),
                                    OLR_Law_ProvID = quoteLawRelDataTable.Rows[i]["ProvInID"].ToString(),
                                    OLR_Law_ProvName = quoteLawRelDataTable.Rows[i]["ProvInName"].ToString(),
                                    OLR_Law_ClauseNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString(),
                                    //  OLR_Law_ClauseNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString(),
                                    OLR_Law_ClauseName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue.ToString(),
                                    //OLR_Law_ItemNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                    ////OLR_Law_ItemNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString(),
                                    //OLR_Law_ItemName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].FormattedValue.ToString(),
                                    OLR_Law_ItemNumber = quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                    OLR_Law_ItemName = quoteLawRelDataTable.Rows[i]["OLR_Law_ItemName"].ToString(),
                                    OLR_Law_HWType = quoteLawRelDataTable.Rows[i]["HWType"].ToString(),
                                    OLR_Law_HWName = quoteLawRelDataTable.Rows[i]["HWName"].ToString(),
                                    OLR_Law_PromuDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["PromuDate"].ToString()),
                                    OLR_Law_LostFlag = quoteLawRelDataTable.Rows[i]["LostFlag"].ToString(),
                                    OLR_Law_ProvNumber = quoteLawRelDataTable.Rows[i]["OLR_Law_ProvNumber"].ToString(),
                                    OLR_LawFlag = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["lawFlag"]),
                                    OLR_LawEffectiveDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["EnforceDate"].ToString()),
                                    HCode = quoteLawRelDataTable.Rows[i]["HCode"].ToString(),
                                    QLR_IsBasicLaw = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"].ToString()) ? DBNull.Value : quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"],

                                    // QLR_IsBasicLaw = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"].ToString()) ? DBNull.Value : quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"],
                                    QLR_ProvType = quoteLawRelDataTable.Rows[i]["QLR_ProvType"].ToString()

                                };
                                sq.OLR_LevelID = !string.IsNullOrEmpty(sq.OLR_Law_ItemNumber) ? 4 : !string.IsNullOrEmpty(sq.OLR_Law_ClauseNumber) ? 3 : !string.IsNullOrEmpty(sq.OLR_Law_ProvID) ? 2 : 1;

                                if (!quoteLawRelBLL.IsExistsP(ccName, ccb.IsParentRealation1(quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString()).CC_ID, sq.OLR_Law_ProvID, sq.OLR_Law_ClauseNumber, sq.OLR_Law_ItemNumber, "", sllModel.LLR_FactLabelXpath))
                                {
                                    //if (quoteLawRelBLL.IsExistsProv(ccName,                             quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString(), sq.OLR_Law_ProvID))
                                    //{
                                    //    if (MessageBox.Show("已存在" + "《" + sq.OLR_LawName + "》" + sq.OLR_Law_ProvName + ",确认添加？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                                    //    {
                                    res = quoteLawRelBLL.Add(sq);
                                }
                                //    }
                                //    //CaseCauseBLL ccb = new CaseCauseBLL();
                                //    //ccb.UpdateXmlPathByCCId(txbxpath.Text.Trim(),                             quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString());
                                //}
                            }
                        }
                        else if (quoteLawRelDataTable.Rows[i]["Name1"].ToString() != "单一")
                        {
                            SYS_QuoteLawRel sq = new SYS_QuoteLawRel
                            {
                                QLR_ID = quoteLawRelDataTable.Rows[i]["QLR_ID"].ToString(),
                                //程序法不保存ID和typeid
                                // OLR_CaseCauseID = sllModel.LLR_CaseCauseID,
                                //OLR_SituationTypeID = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["OLR_SituationTypeID"].ToString()),
                                OLR_LawID = quoteLawRelDataTable.Rows[i]["CATInID"].ToString(),
                                OLR_LawName = quoteLawRelDataTable.Rows[i]["Standardcatname"].ToString(),
                                //OLR_LawName = quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修订") ?
                                //             quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（"))
                                //             : quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修正")
                                //             ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（"))
                                //             : quoteLawRelDataTable.Rows[i]["CATName"].ToString(),
                                OLR_Law_ProvID = quoteLawRelDataTable.Rows[i]["ProvInID"].ToString(),
                                OLR_Law_ProvName = quoteLawRelDataTable.Rows[i]["ProvInName"].ToString(),
                                OLR_Law_ClauseNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString(),
                                //OLR_Law_ClauseNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString()) ? ""
                                //                 : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString(),
                                OLR_Law_ClauseName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue.ToString(),
                                //OLR_Law_ItemNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                ////OLR_Law_ItemNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells[5].Value.ToString(),
                                //OLR_Law_ItemName = dataGridViewData.Rows[i].Cells[5].FormattedValue == null ? ""
                                //                 : dataGridViewData.Rows[i].Cells[5].FormattedValue.ToString(),
                                OLR_Law_ItemNumber = quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                                OLR_Law_ItemName = quoteLawRelDataTable.Rows[i]["OLR_Law_ItemName"].ToString(),
                                OLR_Law_HWType = quoteLawRelDataTable.Rows[i]["HWType"].ToString(),
                                OLR_Law_HWName = quoteLawRelDataTable.Rows[i]["HWName"].ToString(),
                                OLR_Law_PromuDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["PromuDate"].ToString()),
                                OLR_Law_LostFlag = quoteLawRelDataTable.Rows[i]["LostFlag"].ToString(),
                                OLR_Law_ProvNumber = quoteLawRelDataTable.Rows[i]["OLR_Law_ProvNumber"].ToString(),
                                OLR_LawFlag = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["lawFlag"]),
                                OLR_LawEffectiveDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["EnforceDate"].ToString()),
                                HCode = quoteLawRelDataTable.Rows[i]["HCode"].ToString(),
                                QLR_IsBasicLaw = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"].ToString()) ? DBNull.Value : quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"],

                                //QLR_IsBasicLaw = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"].ToString()) ? DBNull.Value : quoteLawRelDataTable.Rows[i]["QLR_IsBasicLaw"],
                                QLR_ProvType = quoteLawRelDataTable.Rows[i]["QLR_ProvType"].ToString()
                            };
                            sq.OLR_LevelID = !string.IsNullOrEmpty(sq.OLR_Law_ItemNumber) ? 4 : !string.IsNullOrEmpty(sq.OLR_Law_ClauseNumber) ? 3 : !string.IsNullOrEmpty(sq.OLR_Law_ProvID) ? 2 : 1;

                            ccName = "组合";

                            if (quoteLawRelBLL.IsExistsP(ccName, "", sq.OLR_Law_ProvID, sq.OLR_Law_ClauseNumber, sq.OLR_Law_ItemNumber, quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString(), ""))
                            {
                                continue;
                            }
                            else
                            {
                                SYS_QuoteLawCondition sqlModel = new SYS_QuoteLawCondition
                                {
                                    QLC_ID = Guid.NewGuid().ToString(),
                                    QLC_CaseType = ccName == "程序法" ? quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString() : "",
                                    QLC_Name = dataGridViewData.Rows[i].Cells["Name1"].Value == null ? "" : dataGridViewData.Rows[i].Cells["Name1"].Value.ToString(),
                                    QLC_Content = dataGridViewData.Rows[i].Cells["txbConditionContent"].Value == null ? "" : dataGridViewData.Rows[i].Cells["txbConditionContent"].Value.ToString(),
                                    QLC_Explain = dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value == null ? "" : dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value.ToString(),
                                    QLC_CaseCauseId = ccName == "组合" ? stiuationType == "2" ? quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString() : ccb.IsParentRealation1(quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString()).CC_ID : "",
                                };
                                if (string.IsNullOrEmpty(sqlModel.QLC_Name) || string.IsNullOrEmpty(sqlModel.QLC_Content) || string.IsNullOrEmpty(sqlModel.QLC_Explain))
                                {
                                    MessageBox.Show("请将配置条件配置完整后再试!");
                                    this.dataGridViewData.Rows[i].DefaultCellStyle.BackColor = Color.GreenYellow;
                                    return;
                                }
                                //string s1= dataGridViewData.Rows[i].Cells["Name1"].Value.ToString();
                                //string s2 = dataGridViewData.Rows[i].Cells["txbConditionContent"].Value.ToString();
                                //string s3 = dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value.ToString();
                                sq.OLR_SituationID = sqlModel.QLC_ID.ToString();

                                if (sq1.AddSYS_QuoteLawCondition(sqlModel))
                                {
                                    res = quoteLawRelBLL.Add(sq);
                                }
                            }
                        }
                    }
                }
                else if (ccName == "程序法"/*||tabPageName == "组合"*/)
                {
                    for (int i = 0; i < quoteLawRelDataTable.Rows.Count; i++)
                    {

                        SYS_QuoteLawRel sq = new SYS_QuoteLawRel
                        {
                            QLR_ID = quoteLawRelDataTable.Rows[i]["QLR_ID"].ToString(),
                            //程序法不保存ID和typeid
                            // OLR_CaseCauseID = sllModel.LLR_CaseCauseID,
                            //OLR_SituationTypeID = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["OLR_SituationTypeID"].ToString()),
                            OLR_LawID = quoteLawRelDataTable.Rows[i]["CATInID"].ToString(),
                            OLR_LawName = quoteLawRelDataTable.Rows[i]["Standardcatname"].ToString(),
                            //OLR_LawName = quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修订") ?
                            //                    quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（"))
                            //                    : quoteLawRelDataTable.Rows[i]["CATName"].ToString().Contains("修正")
                            //                    ? quoteLawRelDataTable.Rows[i]["CATName"].ToString().Substring(0, quoteLawRelDataTable.Rows[i]["CATName"].ToString().IndexOf("（"))
                            //                    : quoteLawRelDataTable.Rows[i]["CATName"].ToString(),
                            OLR_Law_ProvID = quoteLawRelDataTable.Rows[i]["ProvInID"].ToString(),
                            OLR_Law_ProvName = quoteLawRelDataTable.Rows[i]["ProvInName"].ToString(),
                            OLR_Law_ClauseNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString(),
                            //OLR_Law_ClauseNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString()) ? ""
                            //                        : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].Value.ToString(),
                            OLR_Law_ClauseName = dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue == null ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn22"].FormattedValue.ToString(),
                            //OLR_Law_ItemNumber = string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString()) ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString() == "0" ? "" : quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                            ////OLR_Law_ItemNumber = string.IsNullOrEmpty(dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString()) ? "" : dataGridViewData.Rows[i].Cells["dataGridViewTextBoxColumn23"].Value.ToString() == "0" ? "" : dataGridViewData.Rows[i].Cells[5].Value.ToString(),
                            //OLR_Law_ItemName = dataGridViewData.Rows[i].Cells[5].FormattedValue == null ? ""
                            //                        : dataGridViewData.Rows[i].Cells[5].FormattedValue.ToString(),
                            OLR_Law_ItemNumber = quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString(),
                            OLR_Law_ItemName = quoteLawRelDataTable.Rows[i]["OLR_Law_ItemName"].ToString(),
                            OLR_Law_HWType = quoteLawRelDataTable.Rows[i]["HWType"].ToString(),
                            OLR_Law_HWName = quoteLawRelDataTable.Rows[i]["HWName"].ToString(),
                            OLR_Law_PromuDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["PromuDate"].ToString()),
                            OLR_Law_LostFlag = quoteLawRelDataTable.Rows[i]["LostFlag"].ToString(),
                            OLR_Law_ProvNumber = quoteLawRelDataTable.Rows[i]["OLR_Law_ProvNumber"].ToString(),
                            OLR_LawFlag = Convert.ToInt32(quoteLawRelDataTable.Rows[i]["lawFlag"]),
                            OLR_LawEffectiveDate = Convert.ToDateTime(quoteLawRelDataTable.Rows[i]["EnforceDate"].ToString()),
                            HCode = quoteLawRelDataTable.Rows[i]["HCode"].ToString()
                        };
                        sq.OLR_LevelID = !string.IsNullOrEmpty(sq.OLR_Law_ItemNumber) ? 4 : !string.IsNullOrEmpty(sq.OLR_Law_ClauseNumber) ? 3 : !string.IsNullOrEmpty(sq.OLR_Law_ProvID) ? 2 : 1;

                        //if(tabPageName == "组合")
                        //{
                        //    ccName = "组合";
                        //}
                        if (quoteLawRelBLL.IsExistsP(ccName, "", sq.OLR_Law_ProvID, sq.OLR_Law_ClauseNumber, sq.OLR_Law_ItemNumber, quoteLawRelDataTable.Rows[i]["OLR_CaseCauseID"].ToString(), ""))
                        {
                            continue;
                        }
                        else
                        {
                            SYS_QuoteLawCondition sqlModel = new SYS_QuoteLawCondition
                            {
                                QLC_ID = Guid.NewGuid().ToString(),
                                QLC_CaseType = ccName == "程序法" ? stiuationId : "",
                                QLC_Name = dataGridViewData.Rows[i].Cells["Name1"].Value == null ? "" : dataGridViewData.Rows[i].Cells["Name1"].Value.ToString(),
                                QLC_Content = dataGridViewData.Rows[i].Cells["txbConditionContent"].Value == null ? "" : dataGridViewData.Rows[i].Cells["txbConditionContent"].Value.ToString(),
                                QLC_Explain = dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value == null ? "" : dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value.ToString(),
                                QLC_CaseCauseId = ccName == "组合" ? stiuationType == "2" ? stiuationId : ccb.IsParentRealation1(stiuationId).CC_ID : "",
                            };
                            if (string.IsNullOrEmpty(sqlModel.QLC_Name) || string.IsNullOrEmpty(sqlModel.QLC_Content) || string.IsNullOrEmpty(sqlModel.QLC_Explain))
                            {
                                MessageBox.Show("请将配置条件配置完整后再试!");
                                this.dataGridViewData.Rows[i].DefaultCellStyle.BackColor = Color.GreenYellow;
                                return;
                            }
                            //string s1= dataGridViewData.Rows[i].Cells["Name1"].Value.ToString();
                            //string s2 = dataGridViewData.Rows[i].Cells["txbConditionContent"].Value.ToString();
                            //string s3 = dataGridViewData.Rows[i].Cells["txbConditionExplain"].Value.ToString();
                            sq.OLR_SituationID = sqlModel.QLC_ID.ToString();

                            if (sq1.AddSYS_QuoteLawCondition(sqlModel))
                            {
                                res = quoteLawRelBLL.Add(sq);
                            }
                        }


                    }

                }
                if (res)
                {
                    MessageBox.Show("添加成功！");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("添加失败！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请选择数据！");
                return;
            }
        }


        /// <summary>
        /// 数字转中文
        /// </summary>
        /// <param name="number">eg: 22</param>
        /// <returns></returns>
        public string NumberToChinese(int number)
        {
            string res = string.Empty;
            string str = number.ToString();
            string schar = str.Substring(0, 1);
            switch (schar)
            {
                case "1":
                    res = "一";
                    break;
                case "2":
                    res = "二";
                    break;
                case "3":
                    res = "三";
                    break;
                case "4":
                    res = "四";
                    break;
                case "5":
                    res = "五";
                    break;
                case "6":
                    res = "六";
                    break;
                case "7":
                    res = "七";
                    break;
                case "8":
                    res = "八";
                    break;
                case "9":
                    res = "九";
                    break;
                default:
                    res = "零";
                    break;
            }
            if (str.Length > 1)
            {
                switch (str.Length)
                {
                    case 2:
                    case 6:
                        res += "十";
                        break;
                    case 3:
                    case 7:
                        res += "百";
                        break;
                    case 4:
                        res += "千";
                        break;
                    case 5:
                        res += "万";
                        break;
                    default:
                        res += "";
                        break;
                }
                if (str.Substring(1, str.Length - 1).StartsWith("0"))
                {
                    res += "零";
                }
                res += NumberToChinese(int.Parse(str.Substring(1, str.Length - 1)));
            }
            return res;
        }
        /// <summary>
        /// 法规名称单元格点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DV_QuoteLawRel_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (selectedNum == e.RowIndex)
                {
                    return;
                }
                else
                {
                    selectedNum = e.RowIndex;
                }
                this.Cursor = Cursors.WaitCursor;
                hwtype = DV_QuoteLawRel.Rows[e.RowIndex].Cells["HWType"].Value.ToString();
                hwname = DV_QuoteLawRel.Rows[e.RowIndex].Cells["HWName"].Value.ToString().Trim();
                catInid = DV_QuoteLawRel.Rows[e.RowIndex].Cells["CATInID"].Value.ToString();
                catInName = DV_QuoteLawRel.Rows[e.RowIndex].Cells["CATName"].Value.ToString();
                Standardcatname = DV_QuoteLawRel.Rows[e.RowIndex].Cells["Standardcatname"].Value.ToString();
                PromuDate1 = Convert.ToDateTime(DV_QuoteLawRel.Rows[e.RowIndex].Cells["PromuDate"].Value.ToString());
                LostFlag1 = DV_QuoteLawRel.Rows[e.RowIndex].Cells["LostFlag"].Value.ToString();
                IsBasicLaw = DV_QuoteLawRel.Rows[e.RowIndex].Cells["IsBasicLaw"].Value.ToString();
                ProvText.Text = SelectWord.Text = "";
                if (DV_QuoteLawRel.Rows[e.RowIndex].Cells["EffectiveDate"].Value != null)
                {
                    EnforceDate = Convert.ToDateTime(DV_QuoteLawRel.Rows[e.RowIndex].Cells["EffectiveDate"].Value.ToString());
                }
                if (DV_QuoteLawRel.Rows[e.RowIndex].Cells["lawFlag"].Value != null)
                {
                    lawFlag = Convert.ToInt32(DV_QuoteLawRel.Rows[e.RowIndex].Cells["lawFlag"].Value.ToString());
                }
                if (DV_QuoteLawRel.Rows[e.RowIndex].Cells["HCode"].Value != null)
                {
                    HCode = DV_QuoteLawRel.Rows[e.RowIndex].Cells["HCode"].Value.ToString();
                }
                if (buttonName == "查询")
                {
                    if (!string.IsNullOrEmpty(catInid))
                    {
                        treeView1.Nodes.Clear();
                        List<T_Law_Article> provLists = quoteLawRelBLL.GetLawProvData(catInid, provCondition52);
                        if (provLists != null && provLists.Count > 0)
                        {
                            provLists.ForEach(x =>
                            {
                                var node = new TreeNode();
                                node.Text = x.LP_ArticleName;
                                node.Tag = x.LP_ID + "," + x.LP_Article_Number + ",条" + "," + x.BasisType;
                                node.Name = x.LP_Text;
                                if (quoteLawRelBLL.GetNumByProvId(x.LP_ID))
                                {
                                    node.Nodes.Add(new TreeNode());
                                }
                                treeView1.Nodes.Add(node);
                            });
                        }
                    }
                }
                else if (buttonName == "推送")
                {
                    treeView1.Nodes.Clear();
                    StringBuilder str = new StringBuilder();
                    DataTable dt = quoteLawRelBLL.GetLawProvDataByTuiSong(catInid, stiuationType == "2" ? stiuationId : ccb.IsParentRealation1(stiuationId).CC_ID);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        foreach (DataRow item in dt.Rows)
                        {
                            str.Append("'" + item["DataId"] + "',");
                        }
                        string s = str.ToString().Remove(str.Length - 1);
                        DataTable dt1 = quoteLawRelBLL.GetTuiSongData(s);
                        if (dt1 != null && dt1.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt1.Rows.Count; i++)
                            {
                                string str3 = NumberToChinese(Convert.ToInt32(dt1.Rows[i]["ProvNumber"]));
                                if (str3.EndsWith("零")) str3 = str3.Replace("零", "");
                                dt1.Rows[i]["ProvInName"] = "第" + str3 + "条";
                                dt1.Rows[i]["ProvInName"] = dt1.Rows[i]["ProvInName"].ToString().Replace("第一十", "第十");
                            }
                            var arrayDr = dt1.Select();
                            foreach (var provData in arrayDr)
                            {
                                var node = new TreeNode();
                                node.Text = LdFormat.ObjectToString(provData[3]);
                                node.Tag = provData[0] + ",条," + provData[1];
                                node.Name = LdFormat.ObjectToString(provData[2]);
                                if (quoteLawRelBLL.GetNumByProvId(Convert.ToInt32(provData[0].ToString())))
                                {
                                    node.Nodes.Add(new TreeNode());
                                }
                                treeView1.Nodes.Add(node);
                            }
                        }
                    }
                    else
                    {
                        treeView1.Nodes.Clear();
                    }

                }
                this.Cursor = Cursors.Default;
            }
        }

        public DataTable CreateQuoteLawRelTable()
        {
            quoteLawRelDataTable = new DataTable();
            quoteLawRelDataTable.Columns.Add("QLR_ID", typeof(string));
            quoteLawRelDataTable.Columns.Add("OLR_CaseCauseID", typeof(string));
            quoteLawRelDataTable.Columns.Add("OLR_SituationID", typeof(string));
            quoteLawRelDataTable.Columns.Add("OLR_SituationTypeID", typeof(int));
            quoteLawRelDataTable.Columns.Add("HWType", typeof(string));
            quoteLawRelDataTable.Columns.Add("HWName", typeof(string));
            quoteLawRelDataTable.Columns.Add("CATInID", typeof(string));
            quoteLawRelDataTable.Columns.Add("CATName", typeof(string));
            quoteLawRelDataTable.Columns.Add("ProvInID", typeof(string));
            quoteLawRelDataTable.Columns.Add("ProvInName", typeof(string));
            quoteLawRelDataTable.Columns.Add("ClauseInID", typeof(string));
            quoteLawRelDataTable.Columns.Add("OLR_Law_ClauseName", typeof(string));
            quoteLawRelDataTable.Columns.Add("ItemID", typeof(string));
            quoteLawRelDataTable.Columns.Add("OLR_Law_ItemName", typeof(string));
            quoteLawRelDataTable.Columns.Add("PromuDate", typeof(DateTime));
            quoteLawRelDataTable.Columns.Add("LostFlag", typeof(string));
            quoteLawRelDataTable.Columns.Add("OLR_Law_ProvNumber", typeof(string));
            quoteLawRelDataTable.Columns.Add("showindex", typeof(Int32));
            quoteLawRelDataTable.Columns.Add("Name1", typeof(string));
            quoteLawRelDataTable.Columns.Add("MinShiDesc", typeof(string));
            quoteLawRelDataTable.Columns.Add("MinShiXpath", typeof(string));
            quoteLawRelDataTable.Columns.Add("NodeName", typeof(string));
            quoteLawRelDataTable.Columns.Add("ClauseNumber", typeof(string));
            quoteLawRelDataTable.Columns.Add("ItemNumber", typeof(string));
            quoteLawRelDataTable.Columns.Add("EnforceDate", typeof(DateTime));
            quoteLawRelDataTable.Columns.Add("lawFlag", typeof(Int32));
            quoteLawRelDataTable.Columns.Add("HCode", typeof(string));
            quoteLawRelDataTable.Columns.Add("Standardcatname", typeof(string));
            quoteLawRelDataTable.Columns.Add("QLR_IsBasicLaw", typeof(string));
            quoteLawRelDataTable.Columns.Add("QLR_ProvType", typeof(string));
            quoteLawRelDataTable.Clear();
            return quoteLawRelDataTable;
        }

        private void dataGridViewData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && dataGridViewData.Rows.Count >= 1 && e.ColumnIndex != 4 && e.ColumnIndex != 5)
            {
                if (MsgBox.Ask("您确定要删除本条信息吗？") == DialogResult.Yes)
                {

                    dataGridViewData.Rows.RemoveAt(e.RowIndex);
                    //foreach (TreeNode node in treeView1.Nodes)
                    //{
                    //    clearCheck(node);
                    //}
                    // int i= sysExpressSourceTable.Rows.Count;
                    //DataRow[] drs=  sysExpressSourceTable.Select("ES_ID="+ dgvFrmInfoUnit.Rows[e.RowIndex].Cells["ES_ID"].Value.ToString());
                    //  sysExpressSourceTable.Rows.Remove(drs[0]);
                }
            }
        }

        private void clearCheck(TreeNode node)
        {
            if (node.Nodes.Count > 0)
            {
                foreach (TreeNode item in node.Nodes)
                {
                    item.Checked = false;
                    clearCheck(item);
                }
            }
            else
            {
                node.Checked = false;
            }

        }

        /// <summary>
        /// 展开节点树
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            CaseCauseTreeChild(e.Node);
        }

        /// <summary>
        /// 选中节点树
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (!e.Node.Checked)
            {
                return;
            }
            if (ccName == "民事")
            {
                if (cbxType.Text == "单一")
                {
                    if (string.IsNullOrEmpty(txbxpath.Text))
                    {
                        MsgBox.Warn("该节点没有xpath不能添加引用法规");
                        return;
                    }
                }
                //SYS_CaseCause obj = ccb.GetCaseCauseByCCID(stiuationId);
                //if (string.IsNullOrEmpty(obj.XmlPath))
                //{
                //    MsgBox.Warn("该节点没有xpath不能添加引用法规");
                //    return;
                //}
            }

            string provInId = "", provInName = "", provNunber = "", clauseInId = "0", clauseNum = "", clauseName = "", ItemID = "0", ItemNumber = "", ItemName = "", BasisType = "";
            string tag = e.Node.Tag.ToString();
            string[] str = tag.Split(',');
            tag = str[0].ToString();
            string typename = str[2].ToString();
            if (typename == "条")
            {
                provInId = tag;
                // name = e.Node.Name.ToString();
                provNunber = str[1].ToString();
                provInName = e.Node.Text.ToString();
                BasisType = str[3].ToString();
            }
            else if (typename == "款")
            {
                provInName = e.Node.Parent.Text.ToString();
                string[] str1 = e.Node.Parent.Tag.ToString().Split(',');
                provInId = str1[0].ToString();
                provNunber = str1[1].ToString();
                BasisType = str1[3].ToString();

                clauseInId = tag;
                clauseName = e.Node.Text.ToString();
                clauseNum = str[1].ToString();
            }
            else if (typename == "项")
            {
                if (e.Node.Parent.Text.ToString().Contains("款"))
                {
                    provInName = e.Node.Parent.Parent.Text.ToString();
                    string[] str2 = e.Node.Parent.Parent.Tag.ToString().Split(',');
                    provInId = str2[0].ToString();
                    provNunber = str2[1].ToString();
                    BasisType = str2[3].ToString();

                    clauseName = e.Node.Parent.Text.ToString();
                    string[] str1 = e.Node.Parent.Tag.ToString().Split(',');
                    clauseInId = str1[0].ToString();
                    clauseNum = str1[1].ToString();
                    ItemNumber = str[1].ToString();
                    ItemName = e.Node.Text.ToString();
                }
                else if (e.Node.Parent.Text.ToString().Contains("条"))
                {
                    provInName = e.Node.Parent.Text.ToString();
                    string[] str2 = e.Node.Parent.Tag.ToString().Split(',');
                    provInId = str2[0].ToString();
                    provNunber = str2[1].ToString();
                    BasisType = str2[3].ToString();
                    ItemNumber = str[1].ToString();
                    ItemName = e.Node.Text.ToString();
                }
            }

            if (ccName == "刑事" || ccName == "民事" || ccName == "行政执法")
            {
                NodeName.Visible = true;
                string nodes = comboBoxCheckBoxTreeView1.GetCheckNode();
                string[] ss = nodes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length > 0)
                {
                    for (int k = 0; k < ss.Length; k++)
                    {
                        DataRow dr = quoteLawRelDataTable.NewRow();

                        SYS_CaseCause sc = ccb.GetCaseCauseByCCID(ss[k].ToString());
                        //dr["QLR_ID"] = Guid.NewGuid().ToString();
                        dr["QLR_ID"] = "QLR" + DateTime.Now.AddSeconds(k).ToString("yyyyMMddHHmmss");
                        dr["OLR_CaseCauseID"] = sc.CC_ID;
                        dr["OLR_SituationID"] = sc.CC_ID;
                        dr["NodeName"] = sc.CC_Name;
                        dr["OLR_SituationTypeID"] = sc.CC_NodeType;
                        dr["HWType"] = hwtype;
                        dr["HWName"] = hwname;
                        dr["CATInID"] = catInid;
                        dr["CATName"] = catInName;
                        dr["Standardcatname"] = Standardcatname;
                        dr["ProvInID"] = provInId;
                        dr["ProvInName"] = provInName;
                        dr["ClauseInID"] = clauseInId;
                        dr["OLR_Law_ClauseName"] = clauseName;
                        dr["ItemID"] = ItemNumber;
                        dr["OLR_Law_ItemName"] = ItemName;
                        dr["PromuDate"] = PromuDate1;
                        dr["LostFlag"] = LostFlag1;
                        dr["OLR_Law_ProvNumber"] = provNunber;
                        dr["ItemNumber"] = ItemNumber;
                        dr["ClauseNumber"] = clauseNum;
                        dr["EnforceDate"] = EnforceDate;
                        dr["lawFlag"] = lawFlag;
                        dr["HCode"] = HCode;
                        dr["QLR_IsBasicLaw"] = IsBasicLaw;
                        dr["QLR_ProvType"] = BasisType;

                        if (cbxType.Text == "单一" && ccName == "民事")
                        {
                            dr["Name1"] = cbxType.Text;
                            dr["MinShiDesc"] = txbName.Text.Trim();
                            dr["MinShiXpath"] = txbxpath.Text.Trim();
                        }
                        else if (ccName == "刑事" || ccName == "行政执法")
                        {
                            dr["Name1"] = "单一";
                        }
                        DataRow[] dr1 = quoteLawRelDataTable.Select(string.Format(" ProvInID='{0}' and ClauseInID='{1}' and ItemID='{2}' and OLR_CaseCauseID='{3}' ", dr["ProvInID"].ToString(), dr["ClauseInID"].ToString(), dr["ItemID"].ToString(), sc.CC_ID));
                        if (dr1.Length > 0)
                        {
                            return;
                        }
                        //else
                        //{
                        if (e.Node.Checked)
                        {
                            quoteLawRelDataTable.Rows.Add(dr);
                        }
                        else
                        {
                            return;
                        }
                        //  }
                        if (quoteLawRelDataTable != null && quoteLawRelDataTable.Rows.Count > 0)
                        {
                            for (int i = 0; i < quoteLawRelDataTable.Rows.Count; i++)
                            {
                                quoteLawRelDataTable.Rows[i]["showindex"] = i + 1;
                            }
                            dataGridViewData.DataSource = quoteLawRelDataTable;
                            //for (int i = 0; i < quoteLawRelDataTable.Rows.Count; i++)
                            //{
                            //    dataGridViewData.Rows[i].Cells[7].Value = Convert.ToInt32(string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ClauseNumber"].ToString()) ? 0 : quoteLawRelDataTable.Rows[i]["ClauseNumber"]);
                            //    dataGridViewData.Rows[i].Cells[8].Value = Convert.ToInt32(string.IsNullOrEmpty(quoteLawRelDataTable.Rows[i]["ItemNumber"].ToString()) ? 0 : quoteLawRelDataTable.Rows[i]["ItemNumber"]);
                            //}
                        }
                        if (dataGridViewData.Rows.Count > 0)
                        {
                            if (quoteLawRelBLL.IsExistsP(ccName, (ccName == "刑事" || ccName == "行政执法") ? ss[k].ToString() : ccb.IsParentRealation1(ss[k].ToString()).CC_ID, dr["ProvInID"].ToString(), string.IsNullOrEmpty(dr["ClauseInID"].ToString()) ? "" : dr["ClauseInID"].ToString() == "0" ? "" : dr["ClauseInID"].ToString(), string.IsNullOrEmpty(dr["ItemNumber"].ToString()) ? "" : dr["ItemNumber"].ToString() == "0" ? "" : dr["ItemNumber"].ToString(), ss[k].ToString(), txbxpath.Text.Trim()))
                            {
                                dataGridViewData.Rows[quoteLawRelDataTable.Rows.Count - 1].DefaultCellStyle.BackColor = Color.Red;
                            }
                        }
                    }
                    e.Node.Checked = false;

                }
                else if (ss.Length == 0)
                {
                    MsgBox.Err("请选择需要添加法规的节点后再试！");
                    return;
                }
            }
            else if (ccName == "程序法")
            {
                DataRow dr = quoteLawRelDataTable.NewRow();
                NodeName.Visible = false;
                // dr["QLR_ID"] = Guid.NewGuid().ToString();
                dr["QLR_ID"] = "QLR" + DateTime.Now.ToString("yyyyMMddHHmmss");
                dr["OLR_CaseCauseID"] = dr["OLR_SituationID"] = "";
                dr["OLR_SituationTypeID"] = "0";
                dr["HWType"] = hwtype;
                dr["HWName"] = hwname;
                dr["CATInID"] = catInid;
                dr["CATName"] = catInName;
                dr["Standardcatname"] = Standardcatname;
                dr["ProvInID"] = provInId;
                dr["ProvInName"] = provInName;
                dr["ClauseInID"] = clauseInId;
                dr["OLR_Law_ClauseName"] = clauseName;
                dr["ItemNumber"] = ItemNumber;
                dr["OLR_Law_ItemName"] = ItemName;
                dr["PromuDate"] = PromuDate1;
                dr["LostFlag"] = LostFlag1;
                dr["OLR_Law_ProvNumber"] = provNunber;
                dr["EnforceDate"] = EnforceDate;
                dr["lawFlag"] = lawFlag;
                dr["HCode"] = HCode;
                dr["QLR_IsBasicLaw"] = IsBasicLaw;
                dr["QLR_ProvType"] = BasisType;
                DataRow[] dr1 = quoteLawRelDataTable.Select(string.Format(" ProvInID='{0}' and ClauseInID='{1}' and ItemNumber='{2}' ", dr["ProvInID"].ToString(), dr["ClauseInID"].ToString(), dr["ItemNumber"].ToString()));
                if (dr1.Length > 0)
                {
                    if (!e.Node.Checked)
                    {
                        quoteLawRelDataTable.Rows.Remove(dr1[0]);
                    }
                }
                else
                {
                    if (e.Node.Checked)
                    {
                        quoteLawRelDataTable.Rows.Add(dr);
                    }
                    else
                    {
                        return;
                    }
                }
                if (quoteLawRelDataTable != null && quoteLawRelDataTable.Rows.Count > 0)
                {
                    for (int i = 0; i < quoteLawRelDataTable.Rows.Count; i++)
                    {
                        quoteLawRelDataTable.Rows[i]["showindex"] = i + 1;
                    }
                    dataGridViewData.DataSource = quoteLawRelDataTable;
                }

                if (dataGridViewData.Rows.Count > 0)
                {
                    if (quoteLawRelBLL.IsExistsP(ccName, ccName == "刑事" ? stiuationId : ccb.IsParentRealation1(stiuationId).CC_ID, dr["ProvInID"].ToString(), string.IsNullOrEmpty(dr["ClauseInID"].ToString()) ? "" : dr["ClauseInID"].ToString() == "0" ? "" : dr["ClauseInID"].ToString(), string.IsNullOrEmpty(dr["ItemNumber"].ToString()) ? "" : dr["ItemNumber"].ToString() == "0" ? "" : dr["ItemNumber"].ToString(), stiuationId, txbxpath.Text.Trim()))
                    {
                        dataGridViewData.Rows[quoteLawRelDataTable.Rows.Count - 1].DefaultCellStyle.BackColor = Color.Red;
                    }
                }
            }
        }

        /// <summary>
        /// 下级树
        /// </summary>
        /// <param name="parentNode"></param>
        private void CaseCauseTreeChild(TreeNode Node)
        {
            //ProvInID,ProvNumber,ProvText,ArticleName as ProvInName
            List<T_Law_Article> laws = new List<T_Law_Article>();
            string pid = Node.Tag.ToString();// 父级ID
            string[] dr = pid.Split(',');
            pid = dr[0];
            string name = dr[2].ToString();
            if (name == "条")
            {
                //获取款或者项信息根据条ID
                laws = quoteLawRelBLL.GetLawClauseData(Convert.ToInt32(pid));
            }
            else if (name == "款")
            {
                //获取项信息根据款ID
                laws = quoteLawRelBLL.GetLawItemData(Convert.ToInt32(pid));
            }
            if (laws == null || laws.Count == 0)
                return;
            laws.ForEach(x =>
            {
                var node = new TreeNode();
                node.Text = x.LP_ArticleName;
                node.Name = x.LP_Text;
                node.Tag = x.LP_ID + "," + (x.LP_Type == "91" ? x.LP_Paragraph_Number + ",款" : x.LP_Item_Number + ",项");
                //为款则判断款下面是否有项的信息
                if (x.LP_Type == "91" && quoteLawRelBLL.GetLawItemData(x.LP_ID).Count > 0)
                {
                    node.Nodes.Add(new TreeNode());
                }
                Node.Nodes.Add(node);
            });
        }

        /// <summary>
        /// 节点树选中节点树
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node != null)
            {
                ProvText.Text = e.Node.Name.ToString();
                SelectWord.Text = "";
            }
        }


        private void dataGridViewData_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.ColumnIndex == 4)
            //{
            //    string str= dataGridViewData.Rows[e.RowIndex].Cells[4].Value.ToString();
            //    if (!System.Text.RegularExpressions.Regex.IsMatch(dataGridViewData.Rows[e.RowIndex].Cells[4].Value.ToString(), "第[一二三四五六七八九十]款"))
            //    {
            //        MessageBox.Show("输入的款名称格式不正确，请重新输入!");
            //        return;
            //    }
            //}
        }

        private void DV_QuoteLawRel_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in DV_QuoteLawRel.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }

        /// <summary>
        /// 添加条件按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddCondition_Click_1(object sender, EventArgs e)
        {
            int num = 0;
            for (var i = 0; i <= dataGridViewData.Rows.Count - 1; i++)
            {
                var check = (DataGridViewCheckBoxCell)dataGridViewData.Rows[i].Cells["CheckRow"];
                if (Convert.ToBoolean(check.Value))
                {
                    rowIndex = i;
                    num++;
                }
            }
            if (num == 0)
            {
                MessageBox.Show("请选择需要配置的数据后再试！");
                return;
            }
            else if (num > 1)
            {
                MessageBox.Show("请勾选一条数据！");
                return;
            }
            else if (num == 1)
            {
                if (dataGridViewData.Rows[rowIndex].Cells["Name1"].Value == null)
                {
                    NodeTreeCondition objnt = new NodeTreeCondition();
                    objnt.CCName = ccName;
                    if (objnt.ShowDialog() == DialogResult.OK)
                    {
                        TxbConditionName = objnt.TxbConditionName;
                        TxbConditionContent = objnt.TxbConditionContent;
                        TxbConditionExplain = objnt.TxbConditionExplain;

                        dataGridViewData.Rows[rowIndex].Cells["Name1"].Value = TxbConditionName;
                        dataGridViewData.Rows[rowIndex].Cells["txbConditionContent"].Value = TxbConditionContent;
                        dataGridViewData.Rows[rowIndex].Cells["txbConditionExplain"].Value = TxbConditionExplain;
                        Name1.ContextMenuStrip = null;
                    }
                }
                else
                {
                    NodeTreeCondition objnt = new NodeTreeCondition(dataGridViewData.Rows[rowIndex].Cells["Name1"].Value == null ? "" : dataGridViewData.Rows[rowIndex].Cells["Name1"].Value.ToString(),
                       dataGridViewData.Rows[rowIndex].Cells["txbConditionContent"].Value == null ? "" : dataGridViewData.Rows[rowIndex].Cells["txbConditionContent"].Value.ToString(),
                       dataGridViewData.Rows[rowIndex].Cells["txbConditionExplain"].Value == null ? "" : dataGridViewData.Rows[rowIndex].Cells["txbConditionExplain"].Value.ToString(), ccName);
                    if (objnt.ShowDialog() == DialogResult.OK)
                    {
                        TxbConditionName = objnt.TxbConditionName;
                        TxbConditionContent = objnt.TxbConditionContent;
                        TxbConditionExplain = objnt.TxbConditionExplain;
                        dataGridViewData.Rows[rowIndex].Cells["Name1"].Value = TxbConditionName;
                        dataGridViewData.Rows[rowIndex].Cells["txbConditionContent"].Value = TxbConditionContent;
                        dataGridViewData.Rows[rowIndex].Cells["txbConditionExplain"].Value = TxbConditionExplain;
                        Name1.ContextMenuStrip = null;

                    }

                }
            }
        }

        private void 配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rowIndex == -1)
            {
                MessageBox.Show("请选择需要配置的数据后再试！");
                return;
            }
            NodeTreeCondition objnt = new NodeTreeCondition();
            if (objnt.ShowDialog() == DialogResult.OK)
            {
                TxbConditionName = objnt.TxbConditionName;
                TxbConditionContent = objnt.TxbConditionContent;
                TxbConditionExplain = objnt.TxbConditionExplain;
                dataGridViewData.Rows[rowIndex].Cells["Name1"].Value = TxbConditionName;
                dataGridViewData.Rows[rowIndex].Cells["txbConditionContent"].Value = TxbConditionContent;
                dataGridViewData.Rows[rowIndex].Cells["txbConditionExplain"].Value = TxbConditionExplain;
                Name1.ContextMenuStrip = null;
            }
        }

        private void dataGridViewData_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //if (tabPageName != "单一")
            //{
            //    if (e.RowIndex >= 0 && dataGridViewData.Rows.Count >= 1)
            //    {
            //        rowIndex = e.RowIndex;
            //                           // Name1.ContextMenuStrip = contextMenuStrip1;
            //                            //if (MsgBox.Ask("您确定要删除本条信息吗？") == DialogResult.Yes)
            //                            //{

            //                            //    dataGridViewData.Rows.RemoveAt(e.RowIndex);
            //                            //    //foreach (TreeNode node in treeView1.Nodes)
            //                            //    //{
            //                            //    //    clearCheck(node);
            //                            //    //}
            //                            //    // int i= sysExpressSourceTable.Rows.Count;
            //                            //    //DataRow[] drs=  sysExpressSourceTable.Select("ES_ID="+ dgvFrmInfoUnit.Rows[e.RowIndex].Cells["ES_ID"].Value.ToString());
            //                            //    //  sysExpressSourceTable.Rows.Remove(drs[0]);
            //                            //}
            //    }
            //}
        }

        private void colLinkButton_DropDown1_LinkBtnClicked(string value)
        {
            stiuationName = colLinkButton_DropDown1.SelectText;
            stiuationId = colLinkButton_DropDown1.SelectValue;
            stiuationType = colLinkButton_DropDown1.SelectTag;
            if (ccName == "民事")
            {
                SYS_CaseCause obj = ccb.GetCaseCauseByCCID(stiuationId);
                txbxpath.Text = obj.XmlPath;
            }
        }

        private void colLinkButton_DropDown1_LinkBtnDropDownClicked(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                //if (colLinkButton_DropDown1.SelectText == "属性")
                //{

                //}
                DataTable dt = ccb.Select_parentNode_child(value);
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (dt.Rows.Count == 1 && dt.Rows[0]["CC_Name"].ToString() == "属性")
                    {
                        DataTable dt1 = ccb.Select_parentNode_child(value);
                        colLinkButton_DropDown1.AddElement(dt1, "CC_Name", "CC_ID", "CC_NodeType");
                    }
                    else
                    {
                        colLinkButton_DropDown1.AddElement(dt, "CC_Name", "CC_ID", "CC_NodeType");
                    }

                }

            }
        }

        /// <summary>
        /// 类型改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbxType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxType.Text == "单一")
            {
                txbName.Enabled = txbxpath.Enabled = true;
            }
            else
            {
                txbName.Enabled = txbxpath.Enabled = false;
            }
        }
    }
}